<template>
    <div class="ui-footer">
        <div class="ui-footer-bar" :style="styles">
            <div class="ui-footer-bar-left">
                <slot name="left"></slot>
            </div>
            <div class="ui-footer-bar-center">
                <slot></slot>
            </div>
            <div class="ui-footer-bar-right">
                <slot name="right"></slot>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    name: 'FooterBar',
    props: {
        fixed: {
            type: Boolean,
            default: true
        }
    },
    data() {
        return {
            hasSubMenu: false
        }
    },
    computed: {
        menuList () {
            return this.$store.state.app.menuList;
        },
        // 搭配菜单节点使用，有二级菜单的，需要留出二级菜单的留白
        styles() {
            let style = {};
            if(this.fixed) {
                style.position = 'fixed';
                style.right = '0';
                style.bottom = '0';
                style.left = this.hasSubMenu ? '260px' : '130px';
                style.paddingLeft = '20px';
                style.paddingRight = '20px';
                style.boxShadow = '0 0 6px rgba(0, 0, 0, .2)';
                style.zIndex = '196';
                // style.borderLeft = '1px solid #cfcfcf';
            }
            return style;
        }
    },
    watch: {
        '$route': {
            immediate: true,
            handler($route) {
                const name = $route.matched[0]['name'];
                const subMenu = this.menuList.find(item => item.name === name);
                if(subMenu && subMenu.children && subMenu.children.length > 1) {
                    this.hasSubMenu = true;
                }else{
                    this.hasSubMenu = false;
                }
            }
        }
    }
}
</script>

<style>
.ui-footer {
    position: relative;
    height: 60px;
}
.ui-footer-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    height: 60px;
    background-color: #fff;
}
.ui-footer-bar > div {
    display: flex;
    align-items: center;
}
</style>